package com.ctbri.manage.file.util;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

/**
 * ClassName:HttpClientUtil
 * Package:com.ctbri.manage.file.util
 * Description:关于http协议，请求接口的工具类
 *
 * @Author:qs
 * @Create:2023/8/10
 * @Version：1.0
 */
public class HttpClientUtil {

    /***
     * 根据请求路径，请求内容，请求头部内容，使用http方式发送请求
     * @param url
     * @param json
     * @param headers
     * @return String 响应请求结果
     * @throws IOException
     */
    public String doPostJson(String url, String json, Map<String, String> headers) throws IOException {
        String resultString =  "resultString";
      /*  CloseableHttpClient httpClient = HttpClients.createDefault();
        CloseableHttpResponse response = null;
        String resultString = null;

        try {
            HttpPost httpPost = new HttpPost(url);
            if (headers != null) {
                Iterator var8 = headers.keySet().iterator();

                while (var8.hasNext()) {
                    String key = (String) var8.next();
                    httpPost.addHeader(key, (String) headers.get(key));
                }
            }

            StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
            httpPost.setEntity(entity);
            response = httpClient.execute(httpPost);
            resultString = EntityUtils.toString(response.getEntity(), "utf-8");
        } finally {
            if(null !=response) {
                response.close();
            }
        }*/

        return resultString;
    }
}
